package sw6.digipecs.database;

import sw6.digipecs.exceptions.NotSupportedException;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteQuery;

public class Factory<T> implements CursorFactory {

	private Class<T> mClass;

	public Factory(Class<T> c) {
		mClass = c;
	}

	@Override
	public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery,
			String editTable, SQLiteQuery query) {
		if (mClass == PictureCursor.class) {
			return (Cursor) new PictureCursor(db, masterQuery, editTable, query);
		} else {
			throw new NotSupportedException("Factory cannot produce cursor from type");
		}
	}

}
